﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#include "../import/head.h"
#include "../data_struct/pool.h"
#include "../callback/head.h"
#include "../property/head.h"
#include "../threads/head.h"
#include "../variant/head.h"
#include "../big_buf/head.h"
#include "../serial/head.h"
#include "../heart/head.h"
#include "../list/head.h"
#include "../lock/head.h"
#include "../buf/head.h"
#include "../msg/head.h"
#include "hook.h"

namespace xos_box
{

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    hook::hook()
    {
    }

    hook::~hook()
    {
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    int hook::init()
    {
        int ret = 0;

        if( 0 == ret )
        {
            ret = pool::init();
        }

        if( 0 == ret )
        {
            ret = list_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = heart_acceptor::init_all();
        }

        if( 0 == ret )
        {
            ret = heart_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = callback_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = big_buf_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = buf_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = msg_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = serial_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = property_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = variant_impl::init_all();
        }

        if( 0 == ret )
        {
            ret = lock_num::init_all();
        }

        if( 0 == ret )
        {
            ret = lock_obj::init_all();
        }

        return ret;
    }

    int hook::term()
    {
        int ret = 0;

        // 复杂类型放前边
        variant_impl::term_all();
        property_impl::term_all();
        serial_impl::term_all();

        // 
        // i_release obj list should release first
        // 
        list_impl::term_all();

        // 
        // callback
        // 
        callback_impl::term_all();

        // 
        // time
        //
        heart_impl::term_all();
        heart_acceptor::term_all();

        // lock obj
        lock_obj::term_all();
        lock_num::term_all();

        // 
        // buf
        // 
        big_buf_impl::term_all();
        buf_impl::term_all();
        msg_impl::term_all();

        pool::term();

        return ret;
    }

} // xos_box
